import { createApp } from 'vue'
import JTMessageBox from './JTMessageBox.vue'

const MessageBox = (message, option = {}) => {
    return new Promise((resolve, reject) => {
        const mountNode = document.createElement('div')
        const Instance = createApp(JTMessageBox, {
            show: true,
            message,
            ...option,
            confirm: () => {
                Instance.unmount(mountNode)
                document.body.removeChild(mountNode)
                resolve('1')
            },
            close: () => {
                Instance.unmount(mountNode)
                document.body.removeChild(mountNode)
                reject('0')
            }
        })

        document.body.appendChild(mountNode)
        Instance.mount(mountNode)
    })
}

export default MessageBox
